'''
Created on 10 Sep 2009

@author: jack
'''
import GenPrimY
import GenArrayListY
import XmlWriterList
import MathViewer
import GenMarkerTicks
import CCCwriter

GenPrim=GenPrimY.GenPrim
GenArrayList=GenArrayListY.GenArrayList
XmlWriterList=XmlWriterList.XmlWriterList
GenMarkerTicksH=GenMarkerTicks.GenMarkerTicksH
GenMarkerTicksV=GenMarkerTicks.GenMarkerTicksV


def single_dose(shape,array,gaps,gapset,ticks):
#set filename as struc_length_width_(point)__gaps__fieldx(um)_fieldy(um)
    gapslist=''
    for gapsize in range(0,len(gaps[gapset])):
        gapslist+=str(gaps[gapset][gapsize])+'_'
    
    file='t'+str(ticks)+'_'+shape.fname+'_G'+gapslist+'_'+str(array.fieldspan[0][gapset]/1000)+'x'+str(array.fieldspan[1][gapset]/1000)

    #iterate over gaps
    total_shapes=[]
    for gapindex in range(0,len(gaps[gapset])):
        xoffset=array.markersize[0]+array.markersize[2]+gapindex*(array.arraysize[0]+array.arraygap[0])
    
        #Vertical marker
        marker1=GenMarkerTicksV(xoffset,0,3*gapset+gapindex,array)
        
        #Horizontal marker - only for first array
        if gapindex==0:
            Hmarkers=[]
            for h in range(0,len(array.densities)):
                Hmarkertemp=GenMarkerTicksH(0,array.markersize[0]+array.markersize[2]+h*(array.arraysize[1]+array.arraygap[1]),ticks,array)
                Hmarkers.extend(Hmarkertemp)

        #generate each gap size one array at a time.dsds
        dimers=[]
        for d in range(0, len(array.densities)):
            tempdimers=GenArrayList(shape, xoffset, array.markersize[0]+array.markersize[2]+d*(array.arraysize[1]+array.arraygap[1]), gaps[gapset][gapindex], array.densities[d], array.densities[d],array.arraysize[0],array.arraysize[1])
            dimers.extend(tempdimers)
            
        #start the array off empty.
        temp_shapes=[]

        if gapindex==0:
            temp_shapes.extend(Hmarkers);
        temp_shapes.extend(marker1);
        temp_shapes.extend(dimers);
        
        total_shapes.extend(temp_shapes);
        
        #XmlWriterList(temp_shapes, file, gapindex, gaps[gapset]);
           
    MathViewer.MathViewer(total_shapes, file)
    CCCwriter.CCCwriter(total_shapes, file)

